from agv_back.extensions import db
from werkzeug.security import generate_password_hash, check_password_hash


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, index=True)
    # email = db.Column(db.String(254), unique=True, index=True)
    password_hash = db.Column(db.String(128))
    is_admin = db.Column(db.Boolean)

    # location = db.Column(db.String(50))
    # def __init__(self,username,password,is_admin):
    #     self.username = username
    #     self.set_password(password)
    #     self.is_admin = is_admin
    #     super(User, self).__init__()

    def set_password(self, password):
        self.password_hash = generate_password_hash(password)

    def validate_password(self, password):
        return check_password_hash(self.password_hash, password)
